﻿@model CREAPA.Dominio.Portaria

@{
    ViewBag.Title = "Alterar";
}

<script src="~/Scripts/js/JavaScriptUtil.js"></script>
<script src="~/Scripts/js/Parsers.js"></script>
<script src="~/Scripts/js/original/InputMask.js"></script>

<style>
    .flutua {
        display: inline-block;
        margin-right: 3em;    
    }

    #DataPortaria {
    width: 96px;
    height: 10px;
    }
</style>

<script language="javascript">
    function setup() {
        var errorMessage = "Data Invalida: ${value}. Formato Esperado: ${mask}";
        var DataPortaria = new DateMask("dd/MM/yyyy", "DataPortaria");
        DataPortaria.validationMessage = errorMessage;

    }
</script>

    <script>
        $(function () {
            $('#Descricao').ckeditor();
        });

    </script>

<h2>Alterar</h2>

@{    
    var grid = new WebGrid(ViewBag.ListaPortaria); 
}

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

@Html.AntiForgeryToken()
<body onload="setup()">
    <fieldset>
        <legend>Portaria</legend>

        @Html.HiddenFor(model => model.Id)   
<div class="display-label">
             <b>@Html.DisplayNameFor(model => model.Id):</b>
             @Html.DisplayFor(model => model.Id)
         </div>
<br />
        <div class="flutua">
        <div class="editor-label">
            @Html.LabelFor(model => model.IdTipoPortaria)
        </div>
        <div class="editor-field">
            @Html.DropDownList("IdTipoPortaria",  "Selecione") 
            @Html.ValidationMessageFor(model => model.IdTipoPortaria)
        </div>
</div>
<div class="flutua">
<div class="editor-label">
                @Html.LabelFor(model => model.IdAssuntoPortaria)
            </div>
            <div class="editor-field">
                <div class="login-msg">
                    @Html.DropDownList("IdAssuntoPortaria",  "Selecione") 
            @Html.ValidationMessageFor(model => model.IdAssuntoPortaria)
                </div></div>
</div>
<br /><br />
            <div class="editor-label">
                @Html.LabelFor(model => model.Descricao)
            </div>
            <div class="editor-field">
                @Html.TextAreaFor(model => model.Descricao)
            @Html.ValidationMessageFor(model => model.Descricao)
            </div>
            <br />
            <div class="editor-label">
                @Html.LabelFor(model => model.DataPortaria)
            </div>
            <div class="editor-field">
                <div class="login-msg">
                    @Html.EditorFor(model => model.DataPortaria)
                        @Html.ValidationMessageFor(model => model.DataPortaria)
                </div>
            <br />
            <p>
                <div class="editor-label">
                    Observação (opcional):
                </div>
                <div class="editor-field">
                    <div class="login-msg">
                        @Html.TextAreaFor(model => model.DescricaoAnalise)
            @Html.ValidationMessageFor(model => model.DescricaoAnalise)
                    </div>
                    <div style="text-align: right;">
                        <label id="DescricaoAnaliseOut"></label>
                    </div>
                </div>
            </p>

            <p>
                <div class="editor-label">
                    Histórico da Portaria
                </div>
                <div>
                    @grid.GetHtml( tableStyle: "tableAO",
        alternatingRowStyle: "alternateAO",
        headerStyle: "headerAO",
        footerStyle: "footerAO",
        mode: WebGridPagerModes.FirstLast | WebGridPagerModes.NextPrevious,
        firstText: "Primeiro",
        previousText: "Anterior",
        nextText: "Próximo",
        lastText: "Último",columns: grid.Columns(
              grid.Column("DescTipoSituacao", header:"Situacao", format: @<text><center>@item.DescTipoSituacao</center></text>),
              grid.Column("Descricao", header:"Descrição", format: @<text><div style='width: 30em'>@item.Descricao</div></text>),
              grid.Column("Data", header:"Data de Cadastro", format: @<text>@item.Data</text>),
              grid.Column("PessoaCadastrou", header:"Cadastrado por", format: @<text><center>@item.PessoaCadastrou<center></text>)))
                </div>
            </p>

            <p>
                <input type="submit" value="Alterar" class="button" />
                @Html.ActionLink("Voltar", "Index",null,new { @class = "button2" })
            </p>
    </fieldset>
</body>
}


@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

<script>
    jQuery(document).ready(function () {
        // verifica se existe algum elemento com a class
        if ($(".button").length) {
            // adiciona evento desabilitando o botão
            $(".button").on('click', function () {
                $(this).attr({
                    disabled: true
                });
                // descobrindo o form pai e enviando
                this.value = 'Enviando...';
                $(this).parents('form:first').submit();
            });
        }
    });
</script>